package com._9xcloud.leaverequest.web.controller;

import com._9xcloud.leaverequest.web.transfer.Failure;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2015/5/21.
 */
@RestController
@RequestMapping("/error")
public class ErrorController {
    @RequestMapping("/{code}")
    public Failure handleError(@PathVariable int code) {
        try {
            HttpStatus httpStatus = HttpStatus.valueOf(code);
            return new Failure(code, httpStatus.getReasonPhrase());
        } catch (IllegalArgumentException ex) {
            return new Failure(code, "Unknown Error");
        }
    }
}

/*
public class BasicController {
    private Log log = LogFactory.getLog(BasicController.class);

    @ExceptionHandler(SomethingException.class)
    public FailureResponse handleSomethingException(SomethingException e) {
        return new FailureResponse(e.getFailure());
    }

    @ExceptionHandler(TypeMismatchException.class)
    public FailureResponse handleTypeMismatchException(TypeMismatchException e) {
        FailureResponse response = new FailureResponse(SomethingFailure.CLIENT_BADPARAMETER);
        response.setDescription(String.format("�������ͱ�����%s", e.getRequiredType()));
        return  response;
    }

    @ExceptionHandler(MissingServletRequestParameterException.class)
    public Failure handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
        FailureResponse response = new FailureResponse(SomethingFailure.CLIENT_BADPARAMETER);
        response.setDescription(String.format("ȱ�ٲ���%s", e.getParameterName()));
        return  response;
    }
}
*/
